<template>
	<view class="content">
		<view class="list" v-if="dataList&&dataList.length>0">
			<view class="listItem" @click="goNextPage(item)" v-for="item,index in dataList" :key="index">
				<view class="goodsImage">
					<image :src="item.goodsImage" mode="aspectFill"></image>
				</view>
				<view class="goodsName">
					<view>
						{{item.goodsName}}
					</view>
					<view class="price">
						￥{{item.goodsPrice}}
					</view>
				</view>
			</view>
		</view>
		<view class="noSearch" v-else>
			<!-- <image src="/static/icon/home/noSearch.png" alt=""></image> -->
			<view>暂无数据</view>
		</view>
		<view>
			<sysDelModal :title="title" :show="show" @confirm="confirm" @cancel="cancel" />
		</view>
	</view>
</template>

<script>
	import sysDelModal from '@/components/sys-delModal'
	import {
		getList,
		login,
		getUserInfo
	} from '@/common/index.js'
	export default {
		components: {
			sysDelModal,
		},
		data() {
			return {
				dataList: null,
				title: '当前未绑定手机号,前往绑定手机号',
				show: false,
			}
		},
		onLoad() {
			this.payHandle()
			this.getDataList()
		},
		methods: {
			// toJSON() { return this},
			payHandle() {
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log(res);
						const authCode = res.code;
						let data = {
							wechatSign: authCode
						}
						uni.setStorageSync('authCode', authCode)
						this.login(data)
					},
					fail: err => {
						// //console.log('my.getAuthCode 调用失败', err)
					}
				})
				// my.getAuthCode({
				// 	scopes: ['auth_base'],

				// });
			},
			goNextPage(item) {
				wx.exitMiniProgram({
					success: (succ) => {
						console.log(succ);
					},
					fail: (fail) => {
						console.log(fail);
					},
					complete: (complete) => {
						console.log(complete);
					}
				})
				// uni.navigateTo({
				// 	url: '/pages/goodsDetail/goodsDetail?id=' + item.id
				// })
			},
			getDataList() {
				getList().then(res => {
					// let data = JSON.parse(res)
					console.log(res);
					this.dataList = res.data
				})
			},
			login(data) {
				login(data).then((res) => {
					console.log(res);
					if (res.code == 200) {
						let token = res.data.access_token
						uni.setStorageSync('islogin', true)
						uni.setStorage({
							key: 'token',
							data: token,
							success: () => {
								// getUserInfo().then((res) => {
								// 	// console.log(res);
								// 	uni.setStorage({
								// 		key: 'userInfo',
								// 		data: res.data,
								// 		success: function() {
								// 			uni.navigateBack()
								// 		}
								// 	})
								// })
							}
						});
					}
					// if (res.code == 700) {
					// 	this.show = true
					// }
				})
			},
			confirm() {
				uni.navigateTo({
					url: '/pages/loginApp/loginApp'
				})
			},
			cancel() {
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 20rpx;

		.listItem {
			width: 710rpx;
			border-radius: 16rpx;
			overflow: hidden;
			position: relative;

			.goodsImage {
				width: 100%;
				height: 480rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.goodsName {
				position: absolute;
				bottom: 0;
				left: 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 670rpx;
				padding: 20rpx;
				background-color: rgba(0, 0, 0, .5);
				color: #fff;
				font-size: 28rpx;
				font-weight: bold;

				.price {
					color: red;
				}
			}
		}
	}

	.noSearch {
		text-align: center;
		font-weight: 400;
		font-size: 12px;
		color: #999999;
		margin: 0 auto;
		position: relative;
		top: 180rpx;

		image {
			width: 312rpx;
			height: 312rpx;
			margin-top: 68rpx;
			margin-bottom: 68rpx;
		}
	}
</style>